window.dictionariesdb = {
	insert: (dict, call) => {
		if (dict != null) {
			let create_time = dict.create_time;
			let dict_code = dict.dict_code;
			let dict_description = dict.dict_description;
			let dict_name = dict.dict_name;
			let dict_value = dict.dict_value;
			let status = dict.status;
			let sql = 'insert into t_dictionaries (create_time, dict_code, dict_description, dict_name, dict_value, status)' +
				'values' +
				'("' + create_time + '", "' + dict_code + '",  "' + dict_description + '",  "' + dict_name + '",  "' + dict_value +
				'",  "' + status + '")'
			dictionariesdb.select({dict_code}, (data) => {
				if(data != null && data.length > 0){
					dictionariesdb.delete({dict_code}, () => {
						db.excuteSql(sql, () => {
							if (typeof call === 'function') {
								call();
							}
						})
					})
				} else {
					db.excuteSql(sql, () => {
						if (typeof call === 'function') {
							call();
						}
					})
				}
			})
		}
	},
	delete: (params, call) => {
		let sql = 'delete from t_dictionaries where 1=1 ';
		if (params != null) {
			let dict_code = params.dict_code;
			if (dict_code) {
				sql += ' and dict_code="' + dict_code + '"';
			}
		}
		db.excuteSql(sql, () => {
			if (typeof call === 'function') {
				call();
			}
		})
	},
	select: (params, call) => {
		let sql = 'select * from t_dictionaries ';
		if (params != null) {
			let dict_code = params.dict_code;
			if (dict_code) {
				sql += ' where dict_code="' + dict_code + '"';
			}
		}
		db.selectSQL(sql, (data) => {
			if (typeof call === 'function') {
				call(data);
			}
		})
	}
}
